package com.atguigu.staservice.ScheduledTask;

import com.atguigu.staservice.service.StatisticsDailyService;
import com.atguigu.staservice.utils.DateUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * @Auther 赵乾坤
 * @Date 2020-12-07 10:32
 */
@Component
public class ScheuledTask {

    @Autowired
    private StatisticsDailyService staDailyService;

//    @Scheduled(cron = "0/5 * * * * ?")
//    public void testTasj() {
//        System.out.println("-------ScheduledTask-----testTask");
//    }

    //每天凌晨1点执行生成前一日数据
    @Scheduled(cron = "0 0 1 * * ?")
    public void task2() {
        //获取上一天的日期
       String day =   DateUtil.formatDate(DateUtil.addDays(new Date(),-1));
        staDailyService.createStaDaily(day);
    }
}
